package com.xuanner.dt.client;

/**
 * 支持Client工厂的设置
 * Created by xuan on 2018/8/12.
 */
public abstract class DtClientFactoryAware {

    /**
     * Client工厂接口
     */
    private DtClientFactory clientFactory;

    /**
     * Client，这个client放这里貌似有点不合适，后面考虑迁移
     */
    private DtClient client;

    public void setClientFactory(DtClientFactory clientFactory) {
        this.clientFactory = clientFactory;
    }

    protected DtClient getClient() {
        if (null == client) {
            initClient();
        }
        return client;
    }

    private void initClient() {
        if (null == client) {
            //如果是空，使用指定工厂初始化
            this.client = clientFactory.buildClient();
        }
    }

}
